package com.example.deliveryapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class SelectPaymentActivity extends AppCompatActivity {

    private TextView totalAmountTextView;
    private Button payButton;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);

        // 设置内容视图为您的布局XML
        setContentView(R.layout.select_payment_method);
        //返回
        ImageButton return_button = findViewById(R.id.return_button);
        return_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //选择支付方式按钮
        RadioGroup radioGroup = findViewById(R.id.radiogroup_selectpayment_method);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkID) {
                RadioButton radioButton = findViewById(checkID);
                String selectText = radioButton.getText().toString();
            }
        });

        // 初始化 UI 组件
        totalAmountTextView = findViewById(R.id.total_amount_text_view);
        payButton = findViewById(R.id.pay_button);

        // 从 Intent 获取总价
        double totalAmount = getIntent().getDoubleExtra("total_price", 0);

        // 显示总价
        totalAmountTextView.setText(String.format("Total: $%.2f", totalAmount));

        String remarksText = getIntent().getStringExtra("remarks");

        // 设置付款按钮
        payButton.setOnClickListener(v -> {
            // 处理付款逻辑
            Intent orderDetailsIntent = new Intent(SelectPaymentActivity.this, OrderDetailsActivity.class);
            orderDetailsIntent.putExtra("total_price", totalAmount);
            orderDetailsIntent.putExtra("remarks", remarksText); // 将备注信息传递
            startActivity(orderDetailsIntent);
        });
    }
}